<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<div>
		<input type="text"  name="username" placeholder="请输入用户名" id="username"><br>
		<input type="text"  name="password" placeholder="请输入密码" id="password"><br>
		<input type="submit" onclick="login()">
</div>
</body>
<script type="text/javascript">
function login(){
	var username = $("#username").val();
	var password = $("#password").val();
	console.log(username+password);
	if(username === "" ){
		alert("请输入用户名");
		return;
	}
	if(password === "" ){
		alert("请输入密码");
		return;
	}
	
	$.ajax({
		url: "/login",
		type: "post",
		data: {
			"username": username,
			"password":	password
		},
		dataType: "json",
		success : function(r){
			if(r.code == 0){
				location.href = '/index';
			}else{
				alert("error,请重新输入");
			}
		}
	})
	
}
</script>
</html>